package jlib.component.button
{
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import jlib.component.core.LabelBox;

	internal final class LabelButtonFactory
	{
		static public const DEFAULT_ORDER:String = 'defaultOrder';
		static public const DISABLE_ORDER:String = 'disableOrder';
		static public const DEFAULT_WIDTH:Number = 20;
		static public const DEFAULT_HEIGHT:Number = 16;
		
		static public function order($style:String,$width:Number=DEFAULT_WIDTH,$height:Number=DEFAULT_HEIGHT,$label:String=''): Object
		{
			var result:Object;
			switch($style){
				case DEFAULT_ORDER : result = createSkin($label,{up:0x00ffffff,down:0x00ffffff,rollOver:0xffcccccc,rollOut:0xffffff}, {up:0,down:0xff6600,rollOver:0xff8800,rollOut:0}, $width, $height, 'center');
					break;
				case DISABLE_ORDER : result = createSkin($label,{up:0x00000000,down:0x00000000,rollOver:0x00000000,rollOut:0x00000000}, {up:0x777777,down:0x777777,rollOver:0x777777,rollOut:0x777777}, $width, $height, 'center');
					break;
			}
			return result;
		}

		static public function createSkin(text:String='',color:Object=null,fontColor:Object=null,width:Number=DEFAULT_WIDTH,height:Number=DEFAULT_HEIGHT, align:String='left'): Object
		{
			return { up : createLabelBox(text, color.up, fontColor.up, width, height, align),
				down   : createLabelBox(text, color.down, fontColor.down, width, height, align),
				rollOver: createLabelBox(text, color.rollOver, fontColor.rollOver, width, height, align),
				rollOut : createLabelBox(text, color.rollOut, fontColor.rollOut, width, height, align)
			};
		}

		static private function createLabelBox(text:String, color:uint, textColor:uint, width:Number=DEFAULT_WIDTH, height:Number=DEFAULT_HEIGHT, align:String='left'): LabelBox
		{
			var result:LabelBox = new LabelBox;
			result.buttonMode = true;
			result.setFormat(new TextFormat('dotum',12,textColor));
			result.setRound(0);
			result.setAutoSize(TextFieldAutoSize.CENTER);
			result.setBackground(color);
			result.setBorder(1,0xcccccc);
			result.setAlign(align);
			if(!isNaN(width) || !isNaN(height)) result.setSize(width,height);
			else result.setAutoSize(TextFieldAutoSize.LEFT);
			result.setLabel(text);
			return result;
		}
	}//c
}